package com.jueling.culture.controller;

import com.jueling.culture.core.Result;
import com.jueling.culture.core.ResultGenerator;
import com.jueling.culture.model.RoleEditor;
import com.jueling.culture.service.RoleEditorService;
import com.jueling.culture.util.SystemUserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
* @describe 角色编辑权限
* @author linp
* @date 2022/04/30
*/
@RestController
public class RoleEditorController {
    @Autowired
    private RoleEditorService roleEditorService;

    @PostMapping("/api/role/editor")
    public Result add(@RequestBody RoleEditor roleEditor) {
        roleEditorService.saveOrUpdate(roleEditor);
        return ResultGenerator.genSuccessResult();
    }

    @GetMapping("/api/role/editor/{id}")
    public Result detail(@PathVariable Integer id) {
        Integer roleId = id == 0 ? SystemUserUtil.getUserInfo().getRoleId() : id;
        RoleEditor roleEditor = roleEditorService.findById(roleId);
        return ResultGenerator.genSuccessResult(roleEditor);
    }

}
